﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QLHD.Utilities;

namespace STC.Thietbi.Web.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //QLHD.Models.QLHD2013Entities db = new QLHD.Models.QLHD2013Entities();
                //foreach (var item in db.Users.ToList())
                //{
                //    item.PassWord = Utilities.Encrypt("123");
                //}
                //db.SaveChanges();
            }
        }
        protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
        {            
            AuthenticationHelper authen = new AuthenticationHelper();            
            if (authen.Authenticate(LoginUser.UserName, LoginUser.Password))
            {
                //Be authenticated and set the login info to cookie
                authen.SetLoginCookie(LoginUser.UserName, LoginUser.Password, LoginUser.RememberMeSet);               
                if (Request["ReturnUrl"] != null && !string.IsNullOrWhiteSpace(Request["ReturnUrl"]))
                {
                    Response.Redirect(Request["ReturnUrl"]);
                }
                else
                {
                    Response.Redirect("~/ContractsManagement.aspx");
                }
            }
            else
            {
                LoginUser.FailureText = "Tên đăng nhập hoặc mật khẩu không đúng.";
                e.Authenticated = false;
            }
        }
    }
}
